package com.example.springbott.wx_service;

import com.example.springbott.bean.silic.WXUserIndexOrderVo;
import com.example.springbott.mapper.MarketOrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 用户模块
 * @author silic xia
 * @since 2022/11/22 11:50
 */
@Service
public class WXUserServiceImpl implements WXUserService{

    @Autowired
    MarketOrderMapper orderMapper;

    /**
     *  展示index
     *
     * @param /null
     * @return order: {unrecv: 6, uncomment: 1, unpaid: 0, unship: 4} 需要sql语句求值
     *          errmsg: "成功"
     *          errno: 0
     * @author silic xia
     * @since 2022/11/22 11:53
     */
    @Override
    public WXUserIndexOrderVo wxUserIndex(Integer userId) {
        // unrecv 待收——sql语句：select sum(if(confirm_time is null,1,0)) as unrecv from market_order where user_id = #{userId}
        // Integer unrecv = orderMapper.userUnrecvSummary(userId);
        // uncomment 待评——sql语句：select sum(if(comments = 0,1,0)) as uncomment from market_order where user_id = #{userId}
        // Integer uncomment = orderMapper.userUncommentSummary(userId);
        // unpaid 待付——sql语句：select sum(if(pay_id is null,1,0)) as unpaid from market_order where user_id = #{userId}
        // Integer unpaid = orderMapper.userUnpaidSummary(userId);
        // unship 待发——sql语句：select sum(if(ship_time is null,1,0)) as unship from market_order where user_id = #{userId}
        // Integer unship = orderMapper.userUnshipSummary(userId);

        // 方式二，如果为空，需要输出0，而不是null，用int类型
        int unrecv = orderMapper.userUnrecvSummary(userId);  // 301
        int uncomment = orderMapper.userUncommentSummary(userId); // 401
        int unpaid = orderMapper.userUnpaidSummary(userId); // 101
        int unship = orderMapper.userUnshipSummary(userId); // 201


        WXUserIndexOrderVo wxUserIndexOrderVo = new WXUserIndexOrderVo();
        wxUserIndexOrderVo.setUnrecv(unrecv);
        wxUserIndexOrderVo.setUncomment(uncomment);
        wxUserIndexOrderVo.setUnpaid(unpaid);
        wxUserIndexOrderVo.setUnship(unship);
        new WXUserIndexOrderVo();
        return wxUserIndexOrderVo;
    }
}

